﻿package com.eve.eplus.common.view;

import com.eve.eplus.R;
import com.eve.eplus.common.app.BaseApplication;

import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * toast工具
 * @author Norsie
 * @create 12-11-29
 */
public class ComToastTools {
    
    /** 
     * 出现在顶部的Toast
     * @param context 上下文对象 
     * @param msg 要显示的信息 
     */  
    public static void ShowTopMsg(Context context, String msg){  
        int time = Toast.LENGTH_SHORT; 
        Toast toast = Toast.makeText(context, null, time);  
        LinearLayout layout = (LinearLayout)toast.getView();   
//      layout.setBackgroundResource(R.drawable.com_toast);
//      layout.setBackgroundColor(context.getResources ().getColor ( R.color.com_black_color ));  
        layout.setBackgroundColor(Color.parseColor("#00000000"));  
        layout.setOrientation(LinearLayout.HORIZONTAL);
        layout.setGravity(Gravity.CENTER); 
        layout.setLayoutParams(new  LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));     
        TextView mTextView = new TextView(context);  
        mTextView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
        mTextView.setTextColor(context.getResources ().getColor ( R.color.white_color_f ));  
        mTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); 
        mTextView.setGravity(Gravity.CENTER);
        mTextView.setText(Html.fromHtml(msg));  
        mTextView.setBackgroundResource(R.drawable.com_toast);
        layout.addView(mTextView); 
        toast.setGravity(Gravity.TOP, 0,70);
        toast.show();  
    }  
    
    
    /** 
     * 系统原生Toast
     * @param context 上下文对象 
     * @param msg 要显示的信息 
     * @param timeTag 时间参数 若是“s”表示短时间显示   若是“l”（小写L）表示长时间显示 
     */  
    public static void ShowMsg(Context context, String msg, String timeTag){
        int time = Toast.LENGTH_SHORT;  
        if(timeTag == null || "l".equals(timeTag)){  
            time = Toast.LENGTH_LONG;  
        }  
        Toast.makeText(context, msg, time).show();
    }  

}
